package com.hwadee.ems.domain.vo;

import java.time.LocalDateTime;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;

import com.hwadee.ems.domain.po.Exam;
import com.hwadee.ems.service.IUserService;
import com.hwadee.ems.service.IClassService;
import com.hwadee.ems.service.ICourseService;
import com.hwadee.ems.service.ISemesterService;
import com.hwadee.ems.service.IClassroomService;
import com.hwadee.ems.service.impl.UserServiceImpl;
import com.hwadee.ems.service.impl.ClassServiceImpl;
import com.hwadee.ems.service.impl.CourseServiceImpl;
import com.hwadee.ems.service.impl.SemesterServiceImpl;
import com.hwadee.ems.service.impl.ClassroomServiceImpl;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ExamVO {

    @JsonIgnore
    private ICourseService courseService = CourseServiceImpl.getInstance();

    @JsonIgnore
    private IClassService classService = ClassServiceImpl.getInstance();

    @JsonIgnore
    private IClassroomService classroomService = ClassroomServiceImpl.getInstance();

    @JsonIgnore
    private IUserService userService = UserServiceImpl.getInstance();

    @JsonIgnore
    private ISemesterService semesterService = SemesterServiceImpl.getInstance();

    public ExamVO(Exam exam) {
        this.id = exam.getId();
        this.courseId = exam.getCourseId();
        this.courseName = courseService.getById(this.courseId).getName();
        this.classId = exam.getClassId();
        this.className = classService.getById(this.classId).getName();
        this.classroomId = exam.getClassroomId();
        this.classroomName = classroomService.getById(this.classroomId).getName();
        this.invigilatorId = exam.getInvigilatorId();
        this.invigilatorName = userService.getById(this.invigilatorId).getName();
        this.semesterId = exam.getSemesterId();
        this.semester = semesterService.getById(this.semesterId).getName();
        this.startTime = exam.getStartTime();
        this.endTime = exam.getEndTime();
        this.time = startTime.toString().substring(0, 10) 
            + " " + startTime.toString().substring(11, 16) 
            + "~" + endTime.toString().substring(11, 16);
        this.studentCount = exam.getStudentCount();
    }
    
    /**
     * 考试编号
     */
    private Long id;

    /**
     * 课程编号 references course(id) for (name)
     */
    private Long courseId;

    /**
     * 课程名称
     */
    private String courseName;

    /**
     * 考试班级编号 references class(id) for (name)
     */
    private Long classId;

    /**
     * 考试班级名称
     */
    private String className;

    /**
     * 考试教室编号 references classroom(id) for (name)
     */
    private Long classroomId;

    /**
     * 考试教室名称
     */
    private String classroomName;

    /**
     * 监考老师编号 references user(id) for (name)
     */
    private Long invigilatorId;

    /**
     * 考试学期编号 references semester(id) for (name)
     */
    private Long semesterId;

    /**
     * 考试学期
     */
    private String semester;

    /**
     * 监考老师名称
     */
    private String invigilatorName;

    /**
     * 考试开始时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime startTime;

    /**
     * 考试结束时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime endTime;

    /**
     * 考试时间
     */
    private String time;

    /**
     * 考试学生人数
     */
    private Integer studentCount;

}
